package com.wangcang.widgetlibrary.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.time_pick.DateAndTimePickerDialog;
import com.wangcang.widgetlibrary.time_pick.utils.DatePickUtils;

import java.util.ArrayList;
import java.util.List;

public class TimePickActivity extends AppCompatActivity {

    private TextView mTextView;
    private List<String> list = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_pick_main);
        mTextView = (TextView) findViewById(R.id.textView);
        String[] data = getResources().getStringArray(R.array.list);
        for (String str : data) {
            list.add(str);
        }

        //选择年月日
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePickUtils.showDateDialog(TimePickActivity.this, "2017-7-12", new DatePickUtils.OnDateSelectedListener() {
                    @Override
                    public void onDateSelected(String date) {
                        mTextView.setText(date);
                    }
                });
            }
        });

        //选择时分
        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePickUtils.showTimePick(TimePickActivity.this, "17:30", new DatePickUtils.OnTimeSelectedListener() {
                    @Override
                    public void onTimeSelected(String times) {
                        mTextView.setText(times);
                    }
                });
            }
        });

        //单选滚轮
        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePickUtils.showChooseDialog(TimePickActivity.this, list, new DatePickUtils.OnSelectedListener() {
                    @Override
                    public void onSelected(String itemValue, int position) {
                        mTextView.setText(itemValue);
                    }
                } , "选择送货方");
            }
        });

        //年月日时分选择
        findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePickUtils.showDateAndTimeDialog("2017-7-12-11:41", new DateAndTimePickerDialog.Builder(TimePickActivity.this).setMaxYear(2019), new DatePickUtils.OnDateTimeSelectedListener() {
                    @Override
                    public void onDateTimeSelected(String date) {
                        mTextView.setText(date);
                    }
                });
            }
        });
    }

}
